class itemDialog extends renderer.DisplayObjectContainer{

    private nameText:renderer.TextField;
    private attributeText:renderer.TextField;
    // private clickIndex=0;
    private background:renderer.Bitmap;
    private CloseTexture:renderer.Bitmap;

    private backGroundContainer:renderer.DisplayObjectContainer;
    private ItemContainer:renderer.DisplayObjectContainer;

    constructor(){
        super();
        this.backGroundContainer=new renderer.DisplayObjectContainer();
        this.ItemContainer=new renderer.DisplayObjectContainer();

        const dialogBackgroundTexure=new Image();
        const closeTexture=new Image();
        dialogBackgroundTexure.src='dialog.png';
        closeTexture.src="按钮2.png";

        this.addChild(this.backGroundContainer);
        this.addChild(this.ItemContainer);
        

         this.CloseTexture=new renderer.Bitmap(520,200,closeTexture);
        this.CloseTexture.scaleX=this.CloseTexture.scaleY=0.8;
         this.background=new renderer.Bitmap(300,300,dialogBackgroundTexure);
       
        // this.addChild(this.CloseTexture);

        this.CloseTexture.addEventListener("click",()=>{
            console.log(1111111);
            this.dispatchEvent("closeBag",{});
            // OpenNode=" ";
        })

       this.nameText=new renderer.TextField();
       this.nameText.x=100;
       this.nameText.y=100;
       

        this.attributeText=new renderer.TextField();
        this.attributeText.x=200;
        this.attributeText.y=200;
        
        // this.addChild(this.attributeText);

        this.createItemView();
        // this.addChild(this.background);
        this.backGroundContainer.addChild(this.background);
        this.backGroundContainer.addChild(this.CloseTexture);

    }
    createItemView(){
       
        for(let item of packagedItems){
            if(item){
              let clickIndex=0;
              const avatarImage=new renderer.Bitmap(0,0,item.itemAvatarImage);
              avatarImage.x=item.avatarx;
              avatarImage.y=item.avatary;
              clickIndex=item.ClickIndex;
              avatarImage.addEventListener("click",()=>{
                  console.log(88888888888888888);
                  clickIndex++;
                  this.update(item,clickIndex);
                  this.nameText.text=item.name;
                  this.attributeText.text=item.description;
              })
              this.ItemContainer.addChild(avatarImage);
               
            }else{
                
                return ;
            }
        }
       
        

    }
    update(item1:any,click:any){
        if(click==1){
            
        this.ItemContainer.addChild(this.nameText);
        this.ItemContainer.addChild(this.attributeText);
           
        }
        else if(click==2){
          //   this.removeChild(this.nameText);
          //   this.removeChild(this.attributeText);
            if(item1.id==1){
                this.ItemContainer.removeAllChildren();
                packagedItems.splice(packagedItems.indexOf(item1),1);
                user.level++;
                this.createItemView();

            }else{
            this.ItemContainer.removeAllChildren();
            mountedItems.push(item1);
            packagedItems.splice(packagedItems.indexOf(item1),1);
            console.log("package"+packagedItems);
            console.log("mounte"+mountedItems);
            // click=0;
            this.createItemView();
            user.setAttack();
            }
           
        }

        
        
    }
}